﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Veteran_cms.Models
{
    public class TagAutoComplete
    {
        public String tag_id { get; set; }
        public String tag_text { get; set; }

        internal object FindPeople(string searchText, int maxResults)
        {
            List<TagAutoComplete> texts = new List<TagAutoComplete>();

            BuildNameList(texts, searchText);

            //var result = from n in names
            //             where n.FullName.Contains(searchText)
            //             orderby n.FullName
            //             select n;
           
            //return result.Take(maxResults).ToList();
            return texts;
        }
        private static void BuildNameList(List<TagAutoComplete> names, String search)
        {
            Veterandb ctx = new Veterandb();
            IEnumerable<tag> tags = ctx.tags.OrderBy(p=>p.tag_text).ToList();
            foreach (var item in tags)
            {
                if (item.tag_text.ToLower().Contains(search.ToLower()))
                    names.Add(new TagAutoComplete { tag_id = item.tag_id.ToString(), tag_text = item.tag_text });
            }
        }


    }
}